<template>
  <div class="wrap">
    <div id="page">
      <!-- 头部 -->
      <header>
        <!-- <span class="iconfont">&#xe6bc;</span> -->
        <v-back></v-back>
        <h2>小U商城</h2>
        <p>
          <span class="iconfont">&#xf0112;</span>
          <span class="iconfont">&#xe71e;</span>
          <i></i>
        </p>
      </header>
      <!-- 搜索 -->
      <div id="search">
        <input
          type="text"
          class="iconfont"
          v-model="keywords"
          placeholder="&#xe610; 按内容搜索"
        />
      </div>
      <!-- 导航 -->
      <div id="nav">
        <nav>
          <a href="">综合推荐</a>
          <a href="">销量</a>
          <a href="">价格</a>
          <a href="">好评度</a>
          <a href="">店铺</a>
        </nav>
        <p><span class="iconfont">&#xe610;</span> 筛选</p>
      </div>
      <!-- 主体 -->
      <main>
        <p class="text">筛选11.11大促销商品</p>
        <ul>
          <li
            v-for="item in goodsList"
            :key="item.id"
            class="good"
            @click="goodInfo(item.id)"
          >
            <img :src="$pre + item.img" alt="" />
            <div class="commodity">
              <h3>{{ item.goodsname }}</h3>
              <p class="price">
                <em>￥</em><i>{{ item.price }}</i>
                <del>￥{{ item.market_price }}</del
                >999人已付款
              </p>
              <p class="limit">11.11限时299元起</p>
              <p><span>999条评论</span>99.9%好评</p>
            </div>
          </li>
        </ul>
      </main>
    </div>
  </div>
</template>

<script>
import { search, getGoodlist2 } from "../../request/api.js";

export default {
  data() {
    return {
      keywords: "",
      goodsList: [],
    };
  },
  methods: {
    goodInfo(id) {
      this.$router.push("/goodInfo?id=" + id);
    },
  },
  computed: {},
  mounted() {
    //说明是从搜索框跳转过来的
    if (this.$route.query.keywords) {
      this.keywords = this.$route.query.keywords;
      search({ keywords: this.keywords }).then((res) => {
        this.goodsList = res.data.list;
      });
    } else {
      //说明是点击二级分类商品过来的
      // console.log(this.$route.query.id);
      getGoodlist2({ cateid: this.$route.query.id,type:2 }).then((res) => {
        this.goodsList = res.data.list.goodData;
      });
    }
  },
};
</script>

<style scoped>
html,
body,
#page {
  height: 100%;
}
#page {
  max-width: 7.5rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.wrap {
  height: 100vh;
}
/*头部*/
header {
  height: 0.8rem;
  background: #ff6040;
  display: flex;
  color: #ffdfd8;
  padding: 0.3rem 0.12rem 0.12rem 0.33rem;
  align-items: center;
}
header h2 {
  font-size: 0.3rem;
  margin: 0 1.2rem 0 2.55rem;
}
header p {
  width: 1.72rem;
  height: 0.62rem;
  border: 1px solid #ff876c;
  border-radius: 0.31rem;
  line-height: 0.62rem;
  display: flex;
  justify-content: space-between;
  position: relative;
}
header p span {
  width: 0.86rem;
  text-align: center;
}
header p i {
  width: 1px;
  height: 0.37rem;
  background: #ff876c;
  position: absolute;
  left: 0.86rem;
  top: 0.12rem;
}
#search {
  background: linear-gradient(#ff6040, #ff877b);
  text-align: center;
  padding: 0.2rem 0 0.2rem;
  box-sizing: border-box;
}
#search input {
  width: 7.06rem;
  height: 0.6rem;
  border: 0.02rem solid #e6e6e6;
  border-radius: 0.1rem;
}
#search input::placeholder {
  font-size: 0.26rem;
  color: #999999;
  padding-left: 0.22rem;
  box-sizing: border-box;
}
#nav {
  background: linear-gradient(#ff877b, #ff877b);
  padding: 0 0.26rem 0.17rem 0.22rem;
  font-size: 0.26rem;
  display: flex;
  color: #fff;
}
#nav nav {
  width: 5.5rem;
  display: flex;
  justify-content: space-between;
}
#nav nav a {
  color: #fff;
}
#nav p {
  margin-left: 0.4rem;
  padding-left: 0.15rem;
}
#nav p .iconfont {
  font-size: 0.26rem;
}
main {
  flex: 1;
  display: flex;
  overflow: auto;
  flex-direction: column;
  align-items: center;
  background: #fff;
}
main .text {
  width: 95%;
  height: 0.62rem;
  background: #fff4f2;
  font-size: 0.3rem;
  color: #ff6040;
  border: 1px solid #ff6040;
  border-radius: 0.1rem;
  text-align: center;
  line-height: 0.62rem;
  margin-top: 0.2rem;
}
main ul {
  width: 94%;
  margin: 0 auto;
}
main ul li {
  height: 2.2rem;
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
}
main ul li h3 {
  color: #333333;
  font-size: 0.3rem;
}
main ul li p {
  color: #999999;
}
main ul li .price {
  margin: 0.1rem 0;
}
main ul li .price em {
  font-size: 0.14rem;
}
main ul li .price del {
  margin: 0 0.22rem 0 0.07rem;
}
main ul li .price i {
  color: #ff6040;
  font-size: 0.3rem;
}
main ul li .limit {
  padding-left: 0.07rem;
  width: 2.5rem;
  height: 0.33rem;
  background: #ff8066;
  line-height: 0.33rem;
  color: #fff;
  font-size: 0.18rem;
  box-sizing: border-box;
  margin-bottom: 0.15rem;
}
main ul .good img {
  width: 2.5rem;
}
main ul .good h3 {
  width: 4.3rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
footer {
  display: flex;
  height: 1.66rem;
  background: #fff;
  border-top: 1px solid #cccccc;
  padding: 0 0.72rem;
  box-sizing: border-box;
  justify-content: space-between;
}
footer p {
  color: #999999;
  height: 1.66rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
footer p .iconfont {
  font-size: 0.4rem;
}
footer p span {
  font-size: 0.18rem;
}
footer .cur {
  color: #ff6040;
}
</style>